package com.wft.chapter15;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

public class TestFiles {
    public static void main(String[] args) {
        try {
            // 复制文件
            //Files.copy(Paths.get("D:\\Workspaces2018\\crazy-java\\src\\main\\java\\com\\wft\\chapter15\\TestFiles.java"),new FileOutputStream("D:\\Workspaces2018\\crazy-java\\src\\main\\java\\com\\wft\\chapter15\\TestFiles2.java"));

            // 一次性读取文件是所有行
            List<String> allLines = Files.readAllLines(Paths.get("D:\\Workspaces2018\\crazy-java\\src\\main\\java\\com\\wft\\chapter15\\TestFiles.java"));
            for (String line : allLines) {
                System.out.println(line);
            }

            // 直接将多个字符串写入到指定的文件中
            List<String> poem = new ArrayList<>();
            poem.add("wft");
            poem.add("隔壁王二");
            Files.write(Paths.get("D:\\Workspaces2018\\crazy-java\\src\\main\\java\\com\\wft\\chapter15\\TestFiles12.java"), poem);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
